package datas

import (
	gormadapter "github.com/casbin/gorm-adapter/v3"
	"github.com/gookit/color"
	"gorm.io/gorm"
	"os"
)

var Carbines = []gormadapter.CasbinRule{
	{PType: "p", V0: "admin", V1: "/base/login", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/user/register", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/api/createApi", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/api/getApiList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/api/getApiById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/api/deleteApi", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/api/updateApi", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/api/getAllApis", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/auth/createAuthority", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/auth/deleteAuthority", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/auth/getAuthorityList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/auth/setDataAuthority", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/auth/updateAuthority", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/auth/getAuthority", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/menu/getMenu", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/getMenuList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/addBaseMenu", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/getBaseMenuTree", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/addMenuAuthority", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/getMenuAuthority", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/deleteBaseMenu", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/updateBaseMenu", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/menu/getBaseMenuById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/user/changePassword", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/user/getUserList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/user/setUserAuthority", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/user/deleteUser", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/user/updateUser", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/casbin/updateCasbin", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/jwt/jsonInBlacklist", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/system/getSystemConfig", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/system/setSystemConfig", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/system/getServerInfo", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/dictDetail/createDictionaryDetail", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/dictDetail/deleteDictionaryDetail", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/dictDetail/updateDictionaryDetail", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/dictDetail/findDictionaryDetail", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/dictDetail/getDictionaryDetailList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/dict/createDictionary", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/dict/deleteDictionary", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/dict/updateDictionary", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/dict/findDictionaryById", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/dict/getDictionaryList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/sysOperationRecord/createSysOperationRecord", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/sysOperationRecord/deleteSysOperationRecord", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/sysOperationRecord/findSysOperationRecord", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/sysOperationRecord/getSysOperationRecordList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/email/sendEmail", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/company/createCompany", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/company/updateCompany", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/company/deleteCompany", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/company/getCompanyList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/company/getCompanyById", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/company/getCompany", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/department/createDepartment", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/department/updateDepartment", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/department/deleteDepartment", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/department/getDepartmentList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/department/getDepartmentById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/department/getDepartmentByCode", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/station/createStation", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/station/updateStation", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/station/deleteStation", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/station/getStationList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/station/getStationById", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/station/getStationByCode", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/project/getProjectById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/project/createProject", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/project/deleteProject", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/project/getProjectList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/project/updateProject", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/project/exportExcel", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/loginLogs/deleteLoginLogs", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/loginLogs/deleteLoginLogsByIds", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/loginLogs/getLoginLogsList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/createServer", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/updateServer", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/getServerList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/deleteServer", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/getServerById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/updateServerByIdAndStatus", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/getServersByProjectsList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/server/exportExcel", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/security/createSecurity", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/security/updateSecurity", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/security/deleteSecurity", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/security/getSecurityList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/database/createDatabase", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/database/updateDatabase", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/database/deleteDatabase", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/database/getDatabaseList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/database/getDatabaseById", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/database/exportExcel", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/databaseUser/createDatabaseUser", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/databaseUser/updateDatabaseUser", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/databaseUser/deleteDatabaseUser", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/databaseUser/getDatabaseUserList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/databaseUser/getDatabaseUserById", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/domain/createDomain", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/domain/deleteDomain", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/domain/getDomainById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/domain/updateDomain", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/domain/getDomainList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/domain/exportExcel", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/createCluster", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/deleteCluster", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/getClusterList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/updateCluster", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/getClusterById", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/exportExcel", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/createRedisDatabase", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/deleteRedisDatabase", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/updateRedisDatabase", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/getRedisDatabaseList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/data/getDBList/*", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/key/scan", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/key/query", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/cmdb/redis/command/sendCommand", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/basic/getBasicConfigureList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/basic/createBasicConfigure", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/basic/updateBasicConfigure", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/basic/deleteBasicConfigure", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/deploy/dispose/updateAppConfigure", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/deploy/dispose/getAppConfigureList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/deploy/dispose/createAppConfigure", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/dispose/deleteAppConfigure", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/deploy/dispose/copyAppConfigure", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/app/createDeployApp", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/app/deleteDeployApp", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/deploy/app/getAppProjectAuthList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/app/getDeployAppList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/deploy/app/updateDeployApp", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/deploy/build/getDeployBuildList", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/build/getAppGitRepoInfo", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/deploy/build/getDeployAppBranchList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/deploy/build/getDeployAppBranchList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/deploy/build/getAppVirtualList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/createDeployAppJenkins", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/updateDeployAppJenkins", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/deleteDeployAppJenkins", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/startJenkinsJobBuild", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/getJenkinsBuildJobLogs", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/rollbackJenkinsJobBuild", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/deploy/jenkins/createRollbackJenkinsJob", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/jump/filter/updateJumpServerCmdFilter", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/jump/filter/getJumpServerCmdFilterList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/jump/filter/deleteJumpServerCmdFilter", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/jump/filter/createJumpServerCmdFilter", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/jump/logs/updateJumpServerSshLogs", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/jump/logs/getJumpServerSshLogsList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/jump/logs/deleteJumpServerSshLogs", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/jump/logs/deleteJumpServerSshLogsByIds", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/jump/user/getJumpServerUserById", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/jump/user/updateJumpServerUser", V2: "PUT"},
	{PType: "p", V0: "admin", V1: "/jump/user/deleteJumpServerUserByIds", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/jump/user/createJumpServerUser", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/jump/user/deleteJumpServerUser", V2: "DELETE"},
	{PType: "p", V0: "admin", V1: "/jump/user/getJumpServerUserList", V2: "GET"},
	{PType: "p", V0: "admin", V1: "/casbin/updateProjectCasbin", V2: "POST"},
	{PType: "p", V0: "admin", V1: "/casbin/getPolicyProjectByAuthorityId", V2: "GET"},

}

func InitCasbinModel(db *gorm.DB) {
	if err := db.Transaction(func(tx *gorm.DB) error {
		if tx.Where("p_type = ? AND v0 IN ?", "p", []string{"admin"}).Find(&[]gormadapter.CasbinRule{}).RowsAffected == 142 {
			color.Danger.Println("casbin_rule表的初始数据已存在!")
			return nil
		}
		if err := tx.Create(&Carbines).Error; err != nil { // 遇到错误时回滚事务
			return err
		}
		return nil
	}); err != nil {
		color.Warn.Printf("[Mysql]--> casbin_rule 表的初始数据失败,err: %v\n", err)
		os.Exit(0)
	}
}
